package jfprincesstests.fakes;

import jfuzzyprincepless.agents.BaseNegotiationAgent;
import jfuzzyprincepless.zarchive.algorithm.structure.forcnstr.fuzzyfor.IFuzzyForConstruction;
import jfuzzyprincepless.negotiation.INegotiationContext;
import jfuzzyprincepless.zarchive.variables.IFuzzySet;
import jfuzzyprincepless.zarchive.negotiation.services.IExecuteForService;

public class FakeSetTruthDegreeFromFor<E>
	extends BaseNegotiationAgent
{
	private final FakeCondition condition;

	public FakeSetTruthDegreeFromFor(
		FakeCondition condition
	) {
		this.condition = condition;
	}

	@SuppressWarnings("unchecked")
	@Override
	public boolean negotiate(INegotiationContext context) {
		IExecuteForService<E> forServ =
			context.getService(IExecuteForService.class);
		IFuzzyForConstruction<E> forConstr =
			(IFuzzyForConstruction<E>) forServ.getForConstruction();
		IFuzzySet<E> fuzzyForSet = forConstr.getFuzzyForSet();

		E currentElem = forServ.getCurrentElem();
		condition.setTruthDegree(
			fuzzyForSet.getMembershipDegree(currentElem)
		);

		return super.negotiate(context);
	}
}
